import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String[] suit = {"♣","♦","♥","♠"};
    //设置牌的花色

    //获取一副顺序扑克牌
    public List<Poker> buyPoker(){
        List<Poker> pokers = new ArrayList<>();
        for (int i = 0;i < 4;i++){
            for (int j = 0;j < 13;j++){
                Poker poker = new Poker(suit[i],j);
                pokers.add(poker);
            }
        }
        return pokers;
    }

    public void shuffle(List<Poker> pokers){
        for (int i = pokers.size()-1;i>0;i--){
            Random random = new Random();
            //生成一个处于[0,i)范围的值
            int index = random.nextInt(i);
            swap(pokers,i,index);
        }
    }
    public void swap(List<Poker> pokers,int i,int j){
        Poker tmp = pokers.get(i);
        pokers.set(i,pokers.get(j));
        pokers.set(j,tmp);
    }

    //游戏开始
    public List<List<Poker>> game(List<Poker> pokers){
        List<List<Poker>> hand = new ArrayList<>();
        //二维顺序表 表示三个牌手摸走的牌
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        //三个牌手
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //将三个牌手摸走的牌，添加入“摸走的牌”中
        for (int i = 0;i < 5;i++){//三个人摸五轮
            for (int j = 0;j < 3;j++){
                Poker removePoker = pokers.remove(0);
                //牌堆中最上面那张牌被摸走
                hand.get(j).add(removePoker);
                //将摸走的这张牌放入hand中 j下标（第j个牌手）的位置
            }
        }
        return hand;
    }
}
